package com.xuetang9.fujian.utils;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

/**
 * @author: fujian
 * @description: jdbc的工具类
 * @date: 2021/5/15 11:10
 * @version: V1.0
 * @package: com.xuetang9.fujian.utils
 **/
public class JdbcUtil {
    private static Properties properties=null;
    private static final String DataBaseConfig="jdbcConfig/jdbcConfig.properties";
    static {
        properties = new Properties();
        try {
            properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(DataBaseConfig));
            Class.forName(properties.getProperty("jdbc.driver"));
        } catch (IOException | ClassNotFoundException e) {
            e.printStackTrace();
        }
    }


    public static Connection GetConnection() throws SQLException {
        String url = properties.getProperty("jdbc.url");
        String userName = properties.getProperty("jdbc.userName");
        String password = properties.getProperty("jdbc.password");
        return DriverManager.getConnection(url,userName,password);
    }

}
